#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pthread.h>
#include <unistd.h>

#include "UartTool.h"

int fd;
//Control Douyin 控制抖音

void *Rcv_handler(){
	char cmd;
	while(1)
	{
		cmd = 	Getchar(fd);
		switch(cmd)
		{
			case 'P':
				printf("上滑视频\n");
				system("adb shell input swipe 540 500 540 1300 100");
				break;
			case 'N':
				printf("下滑视频\n");
				system("adb shell input swipe 540 1300 540 500 100");
				break;
			case 'Z':
				printf("已点赞\n");
				system("adb shell \"seq 2 | while read i;do input tap 350 1050 & input tap 350 1050 & sleep 0.04;done;\"");
				break;
			case 'C':
				printf("熄屏\n");
				system("adb shell input keyevent 26");
				break;
		}
	}

}

int main(int argc,char **argv)
{
	char deviceName[32] = {'\0'};
	pthread_t Rcv;
	if(argc < 2)
	{
		printf("parm error!\tdo you want input /dev/ttyS?\n");
		return -1;
	}

	strcpy(deviceName,argv[1]);
	if( ((fd = My_serialOpen(deviceName,115200) )== -1)){
		printf("open %s error!\n",deviceName);
		return -1;
	}

	pthread_create(&Rcv,NULL,Rcv_handler,NULL);

	while(1);
	return 0;
}
